﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using RooHui.Infrastructure.Entities.EFContext;
using RooHui.Infrastructure.Entities.Repository;
using RooHui.Infrastructure.Entities.Enum;

namespace RooHui.Infrastructure.Entities.Entity
{
    public class Product : IAccessible<P_Product, Product>, ILogicEntity<P_Product, Product>
    {
        public int ID { get; set; }
        public string ProductName { get; set; }
        public string Summary { get; set; }
        public string RateSummary { get; set; }
        public ItemStatus Status { get; set; }
        public DateTime CreateTime { get; set; }
        public string CreateUser { get; set; }

        protected override void Covariant(P_Product model)
        {
            if (model != null)
            {
                this.ID = model.ID;
                this.ProductName = model.ProductName;
                this.RateSummary = model.RateSummary;
                this.CreateTime = model.CreateTime;
                this.CreateUser = model.CreateUser;
                this.Status = (ItemStatus)model.Status;
                this.Summary = model.Summary;
            }
        }

        protected override P_Product Inverter(Product model)
        {
            if (model != null)
            {
                return new P_Product()
                {
                    ID = model.ID,
                    ProductName = model.ProductName,
                    RateSummary = model.RateSummary,
                    CreateTime = model.CreateTime,
                    CreateUser = model.CreateUser,
                    Status = (int)model.Status,
                    Summary = model.Summary
                };
            }
            return null;
        }

        public Product Set(P_Product dbModel)
        {
            Covariant(dbModel);
            return this;
        }
    }
}
